package com.lgCore.serverProcesser;/**
 * Created by by on 2020/11/13 10:35
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.lgCore.common.LocalSession;
import com.lgCore.protoModel.ProtoMsg;
import com.lgCore.util.ProtoByteUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 心跳异步执行
 *
 * @program: sxreader_rpc
 * @author: ligang
 * @create: 2020-11-13 10:35
 */
public class HeartCallable implements Callable<ProtoMsg.Message> {
    private static final Logger LOGGER = LoggerFactory.getLogger(HeartCallable.class);


    private ProtoMsg.Message message;
    private LocalSession session;
    public HeartCallable(ProtoMsg.Message message, LocalSession localSession){
        this.message = message;
        this.session = localSession;
    }
    @Override
    public ProtoMsg.Message call() throws Exception {
        //处理心跳的数据
        ProtoMsg.Message.Builder responseMsg = ProtoMsg.Message.newBuilder();
        //回复心跳信息
        ProtoMsg.HeartResponse.Builder heartResponse= ProtoMsg.HeartResponse.newBuilder();
        heartResponse.setClientId(message.getHeartRequest().getClientId());
        heartResponse.setResult(true);
        heartResponse.setType(ProtoMsg.HeadType.HEART_RESPONSE);
        responseMsg.setHeartResponse(heartResponse);
        //发送给客户端消息
        session.getChannel().writeAndFlush(ProtoByteUtil.protoToByte(responseMsg));
        return responseMsg.build();
    }
}
